﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Controls;
using System.Windows.Media;

namespace Shrestha.Trigraph
{
    class LegendCanvas : Canvas
    {
        private const int MARKERDIM = 12;
        private const double FONTPADDING = 5;
        private const int MARKERPADDING = 5;
        private const double FONTSIZEY = 12.5;
        private double startx, starty;

        public LegendCanvas()
        {
            starty = 15;
            startx = MARKERPADDING;
        }

        public void Draw()
        {
            double fonty = FONTPADDING;
            foreach (KeyValuePair<string, Brush> kv in TriGraphResources.groupList)
            {
                Plot(startx, starty, fonty, kv.Key, kv.Value);
                starty += MARKERPADDING + MARKERDIM;
                fonty += FONTPADDING + FONTSIZEY;
            }
        }

        private void Plot(double x, double y, double fy, string p, Brush brush)
        {
            LegendMarker lm = new LegendMarker(x, y, MARKERDIM, MARKERDIM, brush);
            TextBlock textBlock = new TextBlock();
            textBlock.Text = p;
            textBlock.HorizontalAlignment = System.Windows.HorizontalAlignment.Right;
            textBlock.Foreground = Brushes.Black;
            textBlock.FontSize = FONTSIZEY;
            Canvas.SetLeft(textBlock, x+MARKERDIM+MARKERPADDING);
            Canvas.SetTop(textBlock, fy);
            this.Children.Add(lm);
            this.Children.Add(textBlock);
        }
   }
}
